
<template>
    <rx-dialog @handOk="handleSubmit" @cancel="cancel">
        <rx-layout>
            <div slot="center">
                <a-form-model ref="form"  :model="mdl" :rules="rules" :label-col="labelCol" :wrapper-col="wrapperCol">
                  <a-row>
                    <a-col :span="12">
                      <a-form-model-item  :label="i18n('form.name','名称')" prop = "name">
                        <a-input :placeholder="i18n('form.name','请输入名称','input')" @blur.native="getPinyinByName" v-model="mdl.name"/>
                      </a-form-model-item>
                    </a-col>
                    <a-col :span="12">
                      <a-form-model-item  :label="i18n('form.key','标识')" prop = "key">
                        <a-input :placeholder="i18n('form.key','请输入标识','input')" v-model="mdl.key"/>
                      </a-form-model-item>
                    </a-col>
                  </a-row>
                  <a-row>
                    <a-col :span="12">
                      <a-form-model-item  :label="i18n('form.isFront','是否前端文件')" prop = "isFront">
                        <a-switch v-model="isFront"/>
                      </a-form-model-item>
                    </a-col>
                    <a-col :span="12">
                      <a-form-model-item  :label="i18n('form.enabled','是否启用')" prop = "enabled">
                        <a-switch v-model="enabled"/>
                      </a-form-model-item>
                    </a-col>
                  </a-row>
                  <a-row>
                    <a-col :span="12">
                      <a-form-model-item  :label="$ti18('rxList.index','序号')" prop = "sn">
                        <a-input-number :min="1" v-model="mdl.sn" />
                      </a-form-model-item>
                    </a-col>
                  </a-row>
                </a-form-model>
            </div>
        </rx-layout>
    </rx-dialog>
</template>
<script>
    import FormCodegenTemplateTypeApi from '@/api/form/codegen/formCodegenTemplateType'
    import {RxDialog,BaseFormModel} from "@lowcode/jpaas-common-lib";


    export default {
      name: 'FormCodegenTemplateTypeEdit',
      mixins: [BaseFormModel],
      components: {
        RxDialog,
      },
      data() {
        return {
          mdl:{
            sn:1
          },
          enabled:false,
          isFront:false,
          rules: {
            enabled: [{required: false, message: this.i18n('form.enabled','请输入是否启用','input'), trigger: 'change'}],
            isFront: [{required: false, message: this.i18n('form.isFront','请输入是否前端文件','input'), trigger: 'change'}],
            key: [{required: true, message: this.i18n('form.key','请输入标识','input'), trigger: 'change'}],
            name: [{required: true, message: this.i18n('form.name','请输入名称','input'), trigger: 'change'}],
          }
        }
      },
      methods: {
        i18n(name,text,key){
          return this.$ti18(name,text,"formCodegenTemplateType",key);
        },
        onload_(data){
          if(data){
            this.enabled=data.enabled=='YES'?true:false;
            this.isFront=data.isFront=='YES'?true:false;
          }
        },
        get(id) {
          return FormCodegenTemplateTypeApi.get(id);
        },
        save() {
          this.mdl.enabled=this.enabled?'YES':'NO';
          this.mdl.isFront=this.isFront?'YES':'NO';
          return FormCodegenTemplateTypeApi.save(this.mdl);
        },
          getPinyinByName(){
              let name=this.mdl.name
              if (!name){
                  return;
              }
              if (this.form && this.mdl.alias){
                  return;
              }
              this.getPinyin(name).then(res => {
                  //去除不可见的特殊符号
                  if(res){
                      res=res.replace(/\u200B/g,'');
                  }
                  this.$set(this.mdl,"key",res)
              })
          }

      }
    }
</script>
<style>
    .relick a{
        margin-right: 10px;
    }

</style>
